package model;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;

import MyScreen.MainPage;

//Day la lop thanh lan thoi gian cua game
public class ThanhLan {
	Image imglan;
	Image imgthanhlan;
	int xtl=20,ytl=150;//toa do cua thanh lan
	int xlan=xtl, ylan=ytl+7;//toa do ban dau cua cuc lan
	int wlan, hlan;//do dong cua cuc lan
	int wtlan, htlan;//do rong cua thanh lan
	int dx = 1;
	int sovong=0;


	public ThanhLan(MainPage mid) {
		try {
			imglan = Image.createImage("/lan.png");
			wlan = imglan.getWidth();
			hlan = imglan.getHeight();
			imgthanhlan = Image.createImage("/thanhlan.png");
			wtlan = imgthanhlan.getWidth();
			htlan = imgthanhlan.getHeight();
		} catch (Exception e) {

		}
	}

	public void draw(Graphics g) {
		
		g.drawImage(imgthanhlan, xtl, ytl, Graphics.TOP | Graphics.LEFT);//ve cai nen
		g.drawImage(imglan, xlan, ylan, Graphics.TOP | Graphics.LEFT);//ve qua bong lan

	}

	public void update() {

		if (xlan + dx + wlan > wtlan + xtl)
			{
			xlan = xtl;
			sovong++;
			}
		else
			xlan = xlan + dx;
	}
	public int getScore()
	{
//		0-60=cool
//		60-100=greate
//		100-150 = perfect
//		150-160=greate
//con lai miss
		int dr=xlan-xtl;
		if (dr<60) return 0;
		if (dr<100) return 1;
		if (dr<150) return 3;
		if (dr<160) return 1;
		
		
		return getmiss();
		
	}
	public int getmiss()
	{
		return 2;
	}
	public int getDistance()
	{
		return (xtl+wtlan)-xlan;
	}
	public int getSovong() {
		return sovong;
	}

	public void setSovong(int sovong) {
		this.sovong = sovong;
	}
	boolean chophepbam=true;
	public boolean isChophepbam() {
		return chophepbam;
	}

	public void setChophepbam(boolean chophepbam) {
		this.chophepbam = chophepbam;
	}

}
